package com.yami.shop.consign.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.dto.AuditParam;
import com.yami.shop.bean.vo.ConsignSituationVO;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.consign.common.model.ConsignSituation;
import com.yami.shop.consign.common.service.ConsignSituationService;
import com.yami.shop.security.platform.model.YamiSysUser;
import com.yami.shop.security.platform.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/admin/consign/situation")
@Tag(name = "admin-寄售信息")
@Slf4j
@AllArgsConstructor
public class ConsignController {

    private final ConsignSituationService consignSituationService;


    @GetMapping("/page")
    @Operation(summary =  "获取寄售商品表列表", description = "获取寄售商品表列表")
    public ServerResponseEntity<PageVO<ConsignSituationVO>> page(@Valid PageDTO pageDTO, ConsignSituation situation) {
        PageVO<ConsignSituationVO> page = consignSituationService.getPage(pageDTO, situation);
        return ServerResponseEntity.success(page);
    }

    @GetMapping("/getById")
    @Operation(summary =  "获取寄售商品记录详情", description = "获取寄售商品记录详情")
    public ServerResponseEntity<ConsignSituation> getInfo(@RequestParam Long id) {
        ConsignSituation one = consignSituationService.getById(id);
        return ServerResponseEntity.success(one);
    }


    @GetMapping("/getListByUserProd")
    @Operation(summary =  "获取寄售列表", description = "获取寄售列表")
    public ServerResponseEntity<List<ConsignSituation>> getListByUserProd(@RequestParam Long userId, @RequestParam Integer prodId) {
        List<ConsignSituation> list = consignSituationService.list(new LambdaQueryWrapper<ConsignSituation>()
                .eq(ConsignSituation::getProdId, prodId).eq(ConsignSituation::getUserId, userId));
        return ServerResponseEntity.success(list);
    }

    @PostMapping("/audit")
    @Operation(summary =  "寄售商品审核", description = "寄售商品审核")
    public ServerResponseEntity<Void> audit(@RequestBody ConsignSituationVO situation) {
        YamiSysUser sysUser = SecurityUtils.getSysUser();
        situation.setAuditUser(sysUser.getUserId());
        consignSituationService.audit(situation, 2);
        return ServerResponseEntity.success();
    }

    @PostMapping("/batchAudit")
    @Operation(summary =  "寄售商品批量审核", description = "寄售商品批量审核")
    public ServerResponseEntity<Void> batchAudit(@RequestBody AuditParam param) {
        consignSituationService.batchAudit(param);
        return ServerResponseEntity.success();
    }







}
